package com.alibaba.cirtus.ots.application.adapter.ability.facade.serviceV2.dp;

import org.apache.commons.lang.time.DateFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DomUtil {

    public final static String DATE_FORMAT = "yyyy-MM-dd";

    public final static String DATE_FORMAT2 = "yyyyMMdd";

    //获取指定日期之前或之后的日期
    public static String getRollbackDate(Date date,int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, days);
        return DateFormatUtils.format(cal.getTime(), DATE_FORMAT2);
    }

    public static Date parse(String dateStr) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT2);
        try {
            return simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }

    public static void main(String[] args) {
        System.out.println(DomUtil.getRollbackDate(parse("20220931"),-3));;
    }

}
